<template>
  <!-- <div class="number-box"> -->
  <ul class="card-num">
    <li :class="(computeNumber.length - index) > 3 ? 'blue' : 'green'" v-for="(item, index) in computeNumber" :key="index">
      <span :ref="'numberDom' + index">0<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9</span>
    </li>
  </ul>
  <!-- </div> -->
</template>

<script>
export default {
  name: 'number-scroll',
  props: {
    number: {
      type: Number,
      default: 0
    },
    unit: {
      type: String,
      default: '个'
    }
  },
  data () {
    return {
      computeNumber: []
    }
  },
  watch: {
    number () {
      this.increaseNumber()
    }
  },
  mounted () {
    this.increaseNumber()
  },
  methods: {
    // 设置数字偏移
    increaseNumber () {
      this.computeNumber = (this.number + '').split('')
      let self = this
      setTimeout(() => {
        self.computeNumber.map((item, index) => {
          self.$refs['numberDom' + index][0].style.transform = `translate(-50%, -${Number(item) * 10}%)`
        })
      }, 200)
    }
  }
}
</script>

<style scoped>
.card-num {
  /* font-weight: 600; */
  display: flex;
  justify-content: flex-start;


}

.card-num li {
  display: inline-flex;
  font-size: 2.25rem;
  width: 35px;
  padding-left: 5px;
  height: 50px;
  line-height: 50px;
  color: #FFFFFF;
  position: relative;
  justify-content: center;
  align-items: baseline;
  margin-right: 0.5rem;
  position: relative;
  overflow: hidden;
  flex-direction: row;
}

.card-num li span {
  z-index: 3;
  position: absolute;
  left: 75%;
  transform: translate(-50%, 0);
  transition: transform 2s;
  display: inline-block;
  width: 100%;
}

.card-num .blue::before,
.card-num .blue::after {
  position: absolute;
  content: " ";

  background: url("../imgs/numbg.png") no-repeat;
  width: 35px;
  height: 50px;
  background-size: 100% 100%;
  margin-right: 0px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: nowrap;
  flex-direction: row;
  align-content: center;
  z-index: 1;
}

.card-num .green::before,
.card-num .green::after {
  position: absolute;
  content: " ";

  background: url("../imgs/numbg.png") no-repeat;
  width: 35px;
  height: 50px;
  background-size: 100% 100%;
  margin-right: 0px;
  padding-bottom: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  flex-wrap: nowrap;
  flex-direction: row;
  align-content: center;
  z-index: 1;
}

.card-num .green::before,
.card-num .blue::before {
  top: 0;
}

.card-num .blue::after,
.card-num .green::after {
  bottom: 0;
}
</style>
